package com.pro.framework.monitor;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class SimpleLogAspect {
    
    @Around("@annotation(logTime)")
    public Object logExecutionTime(ProceedingJoinPoint joinPoint, LogTime logTime) throws Throwable {
        String methodName = logTime.value().isEmpty() ? 
            joinPoint.getSignature().getName() : logTime.value();
        
        long startTime = System.currentTimeMillis();
        
        log.info("🚀 开始执行: {}", methodName);
        
        try {
            Object result = joinPoint.proceed();
            long cost = System.currentTimeMillis() - startTime;
            
            log.warn("✅ 执行完成: {}, 耗时: {}ms", methodName, cost);
            return result;
            
        } catch (Exception e) {
            long cost = System.currentTimeMillis() - startTime;
            log.error("❌ 执行失败: {}, 耗时: {}ms, 错误: {}", methodName, cost, e.getMessage());
            throw e;
        }
    }
}